package com.top75;

import com.bean.TreeNode;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/22 20:51
 */
public class Code1448 {
    public int goodNodes(TreeNode root) {
        return dfs(root,0);
    }

    public int dfs(TreeNode root, int max) {
        if (root == null) {
            return 0;
        }
        int goodNum = root.val > max ? 1 : 0;
        max = Math.max(max, root.val);
        goodNum += dfs(root.left, max);
        goodNum += dfs(root.right, max);
        return goodNum;
    }
}
